import { FormSchema } from '@/components/Form'
import { BasicColumn } from '@/components/Table'
import { DescItem } from '@/components/Description'
import { dicDictList } from '@service/sys/dict'
import { dictConversion } from '@admin/utils'
import { DicSortEnum } from '@enums/basic'
import { TenantIM } from '@type/tenant'

/** 字典查询 */
export const dictMap = await dicDictList(['sys_yes_no', 'sys_normal_disable'])

/** 字典表 */
export const dict: any = {
  YesNoOptions: dictMap['sys_yes_no'],
  NormalDisableOptions: dictMap['sys_normal_disable'],
}

/** 表格数据 */
export const columns: BasicColumn[] = [
  {
    title: '策略Id',
    dataIndex: 'strategyId',
    width: 220,
  },
  {
    title: '租户账号',
    dataIndex: 'name',
    width: 220,
  },
  {
    title: '系统名称',
    dataIndex: 'systemName',
    width: 220,
  },
  {
    title: '租户名称',
    dataIndex: 'nick',
    width: 220,
  },
  {
    title: '租户logo',
    dataIndex: 'logo',
    width: 220,
  },
  {
    title: '账号修改次数',
    dataIndex: 'nameFrequency',
    width: 220,
  },
  {
    title: '超管租户',
    dataIndex: 'isLessor',
    width: 220,
    customRender: ({ record }) => {
      const data = record as TenantIM
      return dictConversion(dict.YesNoOptions, data.isLessor)
    },
    editComponent: 'Select',
    editComponentProps: {
      options: dict.YesNoOptions,
    },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 220,
    customRender: ({ record }) => {
      const data = record as TenantIM
      return dictConversion(dict.NormalDisableOptions, data.status)
    },
  },
  {
    title: '默认租户',
    dataIndex: 'isDefault',
    width: 220,
    customRender: ({ record }) => {
      const data = record as TenantIM
      return dictConversion(dict.YesNoOptions, data.isDefault)
    },
  },
]

/** 查询数据 */
export const searchFormSchema: FormSchema[] = [
  {
    label: '策略Id',
    field: 'strategyId',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '租户账号',
    field: 'name',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '系统名称',
    field: 'systemName',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '租户名称',
    field: 'nick',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '租户logo',
    field: 'logo',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '账号修改次数',
    field: 'nameFrequency',
    component: 'InputNumber',
    colProps: { span: 6 },
  },
  {
    label: '超管租户',
    field: 'isLessor',
    component: 'RadioButtonGroup',
    componentProps: {
      options: dict.YesNoOptions,
    },
    colProps: { span: 6 },
  },
  {
    label: '状态',
    field: 'status',
    component: 'RadioButtonGroup',
    componentProps: {
      options: dict.NormalDisableOptions,
    },
    colProps: { span: 6 },
  },
  {
    label: '默认租户',
    field: 'isDefault',
    component: 'RadioButtonGroup',
    componentProps: {
      options: dict.YesNoOptions,
    },
    colProps: { span: 6 },
  },
]

/** 表单数据 */
export const formSchema: FormSchema[] = [
  {
    label: '策略Id',
    field: 'strategyId',
    component: 'Input',
  },
  {
    label: '租户账号',
    field: 'name',
    component: 'Input',
  },
  {
    label: '系统名称',
    field: 'systemName',
    component: 'Input',
  },
  {
    label: '租户名称',
    field: 'nick',
    component: 'Input',
  },
  {
    label: '租户logo',
    field: 'logo',
    component: 'Input',
  },
  {
    label: '账号修改次数',
    field: 'nameFrequency',
    component: 'InputNumber',
    defaultValue: DicSortEnum.ZERO,
  },
  {
    label: '超管租户',
    field: 'isLessor',
    component: 'RadioButtonGroup',
    componentProps: {
      options: dict.YesNoOptions,
    },
  },
  {
    label: '显示顺序',
    field: 'sort',
    component: 'InputNumber',
    defaultValue: DicSortEnum.ZERO,
  },
  {
    label: '状态',
    field: 'status',
    component: 'RadioButtonGroup',
    componentProps: {
      options: dict.NormalDisableOptions,
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
  },
  {
    label: '默认租户',
    field: 'isDefault',
    component: 'RadioButtonGroup',
    componentProps: {
      options: dict.YesNoOptions,
    },
  },
]

/** 详情数据 */
export const detailSchema: DescItem[] = [
  {
    label: '策略Id',
    field: 'strategyId',
  },
  {
    label: '租户账号',
    field: 'name',
  },
  {
    label: '系统名称',
    field: 'systemName',
  },
  {
    label: '租户名称',
    field: 'nick',
  },
  {
    label: '租户logo',
    field: 'logo',
  },
  {
    label: '账号修改次数',
    field: 'nameFrequency',
  },
  {
    label: '超管租户',
    field: 'isLessor',
    render: (val) => {
      return dictConversion(dict.YesNoOptions, val)
    },
  },
  {
    label: '显示顺序',
    field: 'sort',
  },
  {
    label: '状态',
    field: 'status',
    render: (val) => {
      return dictConversion(dict.NormalDisableOptions, val)
    },
  },
  {
    label: '备注',
    field: 'remark',
  },
  {
    label: '默认租户',
    field: 'isDefault',
    render: (val) => {
      return dictConversion(dict.YesNoOptions, val)
    },
  },
]
